﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XProject.DataVisit.Factory;

namespace XProject.DataVisit.Model.Advertisement
{
    public class Advertisement:IProjectModel
    {
        public virtual Guid PID { get; set; }
        /// <summary>
        /// 广告名称
        /// </summary>
        public virtual string GName { get; set; }
        /// <summary>
        /// 广告URL
        /// </summary>
        public virtual string GUrl { get; set; }
        /// <summary>
        /// 广告备注
        /// </summary>
        public virtual string GRemark { get; set; }
        /// <summary>
        /// 发布者
        /// </summary>
        public virtual Guid Creater { get; set; }
        /// <summary>
        /// 有效期
        /// </summary>
        public virtual int Period { get; set; }
        /// <summary>
        /// 广告来源1表示上传，2表示定制
        /// </summary>
        public virtual string GType { get; set; }
        /// <summary>
        /// 文件夹名称
        /// </summary>
        public virtual string FolderName { get; set; }
        /// <summary>
        /// 流程标志0表示未完成，1表示完成,2表示还在流程中
        /// </summary>
        public virtual int TransfState { get; set; }

        public virtual string TransfS { get {
            switch (TransfState)
            {
                case 0: return "未进入流程";
                case 1: return "通过审核";
                case 2: return "未审核完";
                default: return "未进入流程";
            }
        } }

        /// <summary>
        /// 所属流程
        /// </summary>
        public virtual Guid? BelongFlow { get; set; }
        /// <summary>
        /// 剩余日期
        /// </summary>
        public virtual string SurplusTime {
            get {
                if (DateTime.Compare(Lastupdate.AddDays(Convert.ToDouble(Period)),DateTime.Now)<0)
                    return "已经失效";
                return (Lastupdate.AddDays(Convert.ToDouble(Period)) - DateTime.Now).Days.ToString();
            }
        }

        public virtual DateTime Lastupdate { get; set; }


        public virtual string NTime { get {
            return Lastupdate.ToString("yyyy-MM-dd");
        } }

        public virtual string GT {
            get {
                return GType != "1" ? "定制广告" : "上传广告";
            }
        }

        public virtual UserInfo ChargeUser { get {
            if (Creater != Guid.Empty)
                return DaoFactory.UserInfoDao.GetById(Creater);
            return null;
        } }

        #region 重写Hash和Equals
        public override int GetHashCode()
        {
            return PID.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var temp = obj as Advertisement;
            if (temp == null) return false;
            return temp.PID == this.PID;
        }
        #endregion
    }
}
